package pCloud;

import org.apache.commons.configuration.ConfigurationException;

import pCloud.config.PCloudConfig;

/**
 * Starting point for all experiment. Init PEP, PDP and executes the
 * requests/responses.
 * 
 * The only argument is the configuration file
 * 
 * @author anhdinh
 * 
 */
public class Experiment {

	public static void main(String[] args) throws Exception {
		if (args.length == 0)
			PCloudConfig.init(PCloudConfig.DEFAULT_CONFIG_FILE);
		else
			PCloudConfig.init(args[0]);

		SimplePDP pdp = new SimplePDP(PCloudConfig.getPolicyFiles());

		SimplePEP pep = new SimplePEP(pdp, PCloudConfig.getDatabaseDriver(),
				PCloudConfig.getDatabaseUserName(),
				PCloudConfig.getDatabasePassword());

		String[] requests = PCloudConfig.getRequestFiles();

		SimplePEPResponse resp = null;

		for (int i = 0; i < requests.length; i++) {
			System.out.println("Evaluating request " + requests[i]);
			resp = pep.evaluateRequest(requests[i]);
			System.out.println();
		}
	}
}
